package sg.edu.nus.iss.umpire.service.competition;

import sg.edu.nus.iss.umpire.dao.CompetitionDao;
import sg.edu.nus.iss.umpire.dao.jpa.CompetitionDaoImpl;
import sg.edu.nus.iss.umpire.support.HttpMethod;
import sg.edu.nus.iss.umpire.support.Service;
import sg.edu.nus.iss.umpire.support.ServiceConfig;
import sg.edu.nus.iss.umpire.support.ServiceContext;

@ServiceConfig(path = "competitions/get", method = HttpMethod.GET)
public class GetCompetitionService implements Service {

	@Override
	public String serve(ServiceContext ctx) throws Exception {
		String id = ctx.getRequest().getParameter("id");
		CompetitionDao dao = new CompetitionDaoImpl(ctx.getEntityManager());
		ctx.getRequest().setAttribute(JSON_DATA, dao.getByKey(Long.valueOf(id)));
		return JSON_VIEW;
	}

}
